﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TravelLink.WebModel;
using TravelLink.DAL;

namespace TravelLink.WebApp.UserControl.Member {
    public partial class UC_Member_NewPosition : ControlBase {

        private int _pageSize = 10;
        public int PageSize { get { return _pageSize; } set { _pageSize = value; } }

        protected void Page_Load(object sender, EventArgs e) {
            var dataList = this.DB.TL_Company_Position.Where(u => (u.PeriodTo.HasValue && u.PeriodTo.Value >= DateTime.Now) && (!u.Status.HasValue || (u.Status.HasValue && u.Status.Value != Enum_PositionStatus.Stop))).OrderByDescending(u => u.PublishDate).Take(_pageSize).ToList();
            //dataList[0].TL_City.CName
            this.rptDataSource.DataSource = dataList;
            this.rptDataSource.DataBind();
        }


        protected string BindCity(object dataItem) {
            if (dataItem is TL_Company_Position) {
                var source = (dataItem as TL_Company_Position);
                if (source != null && source.TL_City != null) {
                    return source.TL_City.CName;
                }
                return string.Empty;
            }
            return string.Empty;
        }


        protected string BindPositionStatus(object dataItem) {
            if (dataItem is TL_Company_Position) {
                var source = (dataItem as TL_Company_Position);
                if (source != null) {
                    return Enum_PositionStatus.Resolve(source.Status);
                }
                return string.Empty;
            }
            return string.Empty;
        }
    }
}